package top.bug.blog.controller.backend;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import top.bug.blog.annotation.Auth;
import top.bug.blog.common.Result;
import top.bug.blog.entity.dto.category.CategoryAddRequest;
import top.bug.blog.entity.dto.category.CategoryQueryRequest;
import top.bug.blog.entity.dto.category.CategoryUpdateRequest;
import top.bug.blog.entity.dto.common.BatchRequest;
import top.bug.blog.entity.dto.common.OrderModRequest;
import top.bug.blog.entity.po.Category;
import top.bug.blog.service.CategoryService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author <a href="https://github.com/jiusi66">九思.</a>
 * @email 10837907@qq.com
 * @from <a href="https://www.52bug.top">递归茶馆-www.52bug.top</a>
 * @description 后台-分类模块
 */
@Api(tags = "分类管理模块")
@RestController
@RequestMapping("/categoryApi")
@Auth
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @PostMapping("/getList")
    @ApiOperation("获取列表")
    public Result<Page<Category>> getList(@RequestBody CategoryQueryRequest queryRequest) {
        return Result.success(categoryService.getList(queryRequest));
    }

    @GetMapping("/getAll")
    @ApiOperation("获取分类集合")
    public Result<List<Category>> getAll() {
        return Result.success(categoryService.getAllCategory());
    }

    @PostMapping("/add")
    @ApiOperation("新增数据")
    public Result<Boolean> add(@RequestBody CategoryAddRequest addRequest) {
        return Result.success(categoryService.add(addRequest));
    }

    @PostMapping("/edit")
    @ApiOperation("编辑数据")
    public Result<Boolean> edit(@RequestBody CategoryUpdateRequest updateRequest) {
        return Result.success(categoryService.edit(updateRequest));
    }

    @PostMapping("/delete")
    @ApiOperation("批量删除")
    public Result<Boolean> delete(@RequestBody BatchRequest batchRequest) {
        return Result.success(categoryService.delete(batchRequest));
    }

    @PostMapping("/editOrder")
    @ApiOperation("修改排序")
    public Result<Boolean> editOrder(@RequestBody OrderModRequest orderModRequest) {
        return Result.success(categoryService.editOrder(orderModRequest));
    }

}